package com.hmall.mapper;

import com.hmall.model.MallOrder;
import com.hmall.model.MallOrderItem;
import com.hmall.model.MallProductPlanItem;
import com.hmall.util.MyMapper;
import com.hmall.vo.CartProductTempVo;
import com.hmall.vo.MallOrderItemManageVo;
import com.hmall.vo.OrderSelectItemVo;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Repository
public interface MallOrderItemMapper extends MyMapper<MallOrderItem> {
    List<MallOrderItem> getByOrderNoUserId(@Param("orderNo")Long orderNo, @Param("userId")Integer userId);
    List<MallOrderItemManageVo> selectByOrderNo(Long order_no);
    List<MallOrderItem> getByOrderNo(@Param("orderNo")Long orderNo);
    Integer deleteByOrderNo(@Param("orderNo") Long orderNo);
    Integer selectOrderId(@Param("id") Integer id);
    Integer updateOrderItem(@Param("id")Integer id,@Param("current_unit_price")BigDecimal current_unit_price, @Param("quantity")Integer quantity,@Param("total_price")BigDecimal total_price);
//批量添加产品明细
    int batchInsert(@Param("orderNo")Long orderNo,@Param("userId")Integer userId,@Param("itemList") List<OrderSelectItemVo> itemList);
//添加产品明细
    int insertQuk(@Param("orderNo")Long orderNo,@Param("userId")Integer userId,@Param("productId")Integer productId,
               @Param("producName")String producName,@Param("productMainImage")String productMainImage,
               @Param("productPrice")Double productPrice,@Param("weight")Integer weight,
               @Param("productTotalPrice")Double productTotalPrice,@Param("grade")String grade,
                  @Param("commentCheck")Integer commentCheck,
                  @Param("productModel")String productModel
                );

    //找出产品明细表里的具体某个用户的所有的产品id
    List<Integer> findProductListByUser(@Param("userId") Integer userId);


    //根据用户id查询出未评价的订单
    List<MallOrderItem> findOrderItemByUser(@Param("userId") Integer userId, @Param("unComment") int unComment, @Param("pageStart") int pageStart, @Param("pageSize") int pageSize);

    //计算上述的总数
    int findProductListByUserCount(@Param("userId") Integer userId, @Param("unComment") int unComment);

    //列出所有相同的订单的销量
    List<Map<String, Object>> listGroupByProductId(@Param("successOrderList") List<BigInteger> successOrderList);

    //根据订单的id查询出productId
    int findProductIdByOrderItemId(@Param("orderItemId") Integer orderItemId);

    //组合查询 根据订单编号查询订单明细
    List<MallOrderItem> findOrderItemByOrderList(@Param("successOrderId") List<BigInteger> successOrderId,
                                                 @Param("unComment") Integer unComment,
                                                 @Param("pageStart") Integer pageStart,
                                                 @Param("pageSize") Integer pageSize);

    //组合查询 根据订单编号查询订单明细的数目
    int findOrderItemCountByOrderList(@Param("successOrderId") List<BigInteger> successOrderId,
                                      @Param("unComment") int unComment);

    void deleteByUserId(@Param("userId") Integer userId);

    void updateQuantity(@Param("id") Integer id, @Param("quantity") Integer quantity);

    List<MallOrderItem> selectByMonth(@Param("dealer_id") Integer dealer_id,@Param("startTime") Date startTime,@Param("endTime") Date endTime);

    List<MallOrderItem> selectByUserIdAndMonth(@Param("user_id") int user_id, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    List<MallOrderItem> selectProductMonthData(@Param("product_id") int product_id,@Param("dealer_id") int dealer_id,@Param("startTime") Date startTime,@Param("endTime") Date endTime);

    Integer checkResidualQuantity(@Param("orderNo") Long orderNo);
}